package com.hndzyu.yd.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.hndzyu.yd.R;

/**
 * Created by zz9527 on 2018/11/5.
 */
public class TXDialog extends Dialog {
    TextView tvTitle;
    TextView tvTrue;
    ImageView ivHead;

    private TXDialog.TXListener mListener;

    public void setListener(TXListener listener) {
        mListener = listener;
    }

    public TXDialog(@NonNull Context context) {
        super(context, R.style.my_dialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (null != getWindow()) {
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.dimAmount = 0.5f;
            getWindow().setAttributes(lp);
        }
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        setContentView(R.layout.dialog_tx);
        tvTrue = findViewById(R.id.tv_true);
        tvTitle = findViewById(R.id.tv_title);
        ivHead = findViewById(R.id.iv_head);
        tvTrue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.checktrue();
            }
        });
        setCanceledOnTouchOutside(true);
    }

    //设置弹框内容
    public void showMsg(String msg) {
        tvTitle.setText(msg);
    }

    public void showImg(int imgId) {
        ivHead.setImageResource(imgId);
    }

    public interface TXListener {
        void checktrue();
    }
}
